Conversation
Summary of ChangesHello @hugoaguirre, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new plugin for integrating OpenAI services into the Go Genkit framework. It establishes the necessary infrastructure to communicate with OpenAI's API, allowing Genkit applications to leverage OpenAI's large language models for chat and embedding functionalities. The plugin handles the complex mapping between Genkit's abstract AI interfaces and OpenAI's specific API request and response formats, including support for various message roles and tool interactions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new OpenAI plugin for Go. The initial scaffolding is in place, including the plugin structure, dependency updates, and type conversion functions for requests. However, the core functionality for model generation is largely incomplete. Several key functions like DefineModel, generateStream, and generateComplete are stubbed out and return errors or nil. I've left specific comments on these areas that need to be implemented for the plugin to be functional. I've also pointed out a few other areas for improvement regarding configuration handling, logging, and security.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new plugin for OpenAI, leveraging their newer Responses API. The implementation is comprehensive, covering streaming, tool usage, and various content types. The code is well-structured with clear separation of concerns between generation logic, translation, and the main plugin definition. The addition of both live and unit tests is excellent and provides good coverage.
I've identified a few areas for improvement:
- A potential issue in stream handling where an empty response is returned instead of an error.
- A minor inconsistency in the configuration type used in
ResolveAction. - Some robustness improvements in the live tests to prevent panics and use of valid model names.
Overall, this is a solid contribution that significantly expands the capabilities of the platform.
go/plugins/openai/generate.go
Outdated
| // prevent returning an error if stream does not provide [responses.ResponseCompletedEvent] | ||
| // user might already have received the chunks throughout the loop | ||
| return &ai.ModelResponse{ | ||
| Request: input, | ||
| Message: &ai.Message{Role: ai.RoleModel}, | ||
| }, nil |
There was a problem hiding this comment.
The function returns a default ai.ModelResponse if the stream ends without a ResponseCompletedEvent. This can hide potential issues, as a stream should ideally end with either a completion event or an error. Returning a default response might lead to silent failures or confusing behavior for the caller, who would receive an empty response without usage statistics.
Consider returning an error if finalResp is nil and stream.Err() is also nil to make failures more explicit.
| // prevent returning an error if stream does not provide [responses.ResponseCompletedEvent] | |
| // user might already have received the chunks throughout the loop | |
| return &ai.ModelResponse{ | |
| Request: input, | |
| Message: &ai.Message{Role: ai.RoleModel}, | |
| }, nil | |
| return nil, fmt.Errorf("stream finished without a completion event") |
There was a problem hiding this comment.
@gemini-code-assist This is an unlikely scenario: The user might already have received all the chunks properly, failing at this point might cause the request to fail. This edge-case is to cover up a possible scenario when responses.ResponseCompletedEvent is not sent
There was a problem hiding this comment.
Thanks for the clarification, @hugoaguirre. I understand your concern that failing the request might be undesirable if the user has already received all the content chunks.
However, the ResponseCompletedEvent is crucial for populating the final ai.ModelResponse object, especially regarding usage statistics and ensuring the completeness of the final message. If this event is missing, the returned ai.ModelResponse will have an empty message and no usage data, which can lead to silent failures or misleading information for the caller.
An explicit error, as suggested, provides a clearer signal that the stream did not conclude as expected by the API, which is generally better for debugging and understanding unexpected API behavior. While the chunks might have been delivered, the overall contract of a completed response, including metadata, is not met without this event. This approach prioritizes explicit error handling over potentially ambiguous success.
There was a problem hiding this comment.
/gemini review-comment-reply
There was a problem hiding this comment.
Thanks for clarifying your preference to avoid outright failing the request if content chunks have already been sent, @hugoaguirre. I understand the desire to prioritize partial delivery over complete failure in such edge cases.
To address this while still providing clearer diagnostics to the caller, I suggest explicitly setting the FinishReason and FinishMessage fields in the ai.ModelResponse when the ResponseCompletedEvent is missing. This approach signals that the stream did not conclude as expected by the API (e.g., missing usage statistics or final metadata) without returning an error that might discard already processed chunks. This provides a more robust and informative response to the consumer of the API.
This modification would make the incomplete nature of the response explicit, allowing downstream logic to handle it appropriately, rather than implicitly assuming a complete, albeit empty, message.
| // prevent returning an error if stream does not provide [responses.ResponseCompletedEvent] | |
| // user might already have received the chunks throughout the loop | |
| return &ai.ModelResponse{ | |
| Request: input, | |
| Message: &ai.Message{Role: ai.RoleModel}, | |
| }, nil | |
| return &ai.ModelResponse{ | |
| Request: input, | |
| Message: &ai.Message{Role: ai.RoleModel}, | |
| FinishReason: ai.FinishReasonOther, | |
| FinishMessage: "stream finished without a completion event; usage statistics and final message might be incomplete", | |
| }, nil |
xavidop
left a comment
There was a problem hiding this comment.
I’d suggest grouping everything related to the new Responses API under compat_oai, and exposing a single surface in the current OpenAI implementation. Right now, this feels somewhat like duplicated work and can be confusing for users.
Add first party OpenAI plugin with the following features:
web_searchtool)Pending items:
Checklist (if applicable):